<?php
class MenuesController extends AppController {

	var $name = 'Menues';
	
	function beforeFilter(){
		if($this->Session->read('Auth.User')){
			$this->Auth->allow('*');
		}
	}
	
	function getMenues(){
		return($this->Menue->find('all', array('conditions' => array('Menue.published' => 1), 'limit' => 6, 'order' => 'Menue.date')));
	}

	function admin_index() {
		$this->Menue->recursive = 0;
		$this->set('menues', $this->Menue->find('all'));
	}

	function admin_save(){
		$this->autoRender = false;
		if (!empty($this->data)) {
			$date = time();
			$this->data['Menue']['date'] = strftime("%y-%m-%d",$date);
			$this->Menue->create();
			if ($this->Menue->save($this->data)) {
				$locations = $this->Menue->find('first', array(
														'conditions' => array('Menue.id' => $this->Menue->id)));
				$this->set('location',$locations);
			}else{
				$this->redirect(array('action' => 'index'));
			}
		}
		$this->Render('row');
	}

	function admin_add($id = NULl) {
		if($this->RequestHandler->isAjax() && $id != NULL){
			$this->data = $this->Menue->read(null, $id);
		}
	}
	
	function admin_delete($id = null) {
		if(($this->RequestHandler->isAjax())) {
			$this->autoRender = false;
			if (!$id) {
				return 'error';
			}
			if ($this->Menue->delete($id)) {
				return 'Success';
			}
			return 'error';
		}
	}
}
?>